package com.lxhll.personnel.service.impl;

import java.time.LocalDate;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lxhll.personnel.core.P;
import com.lxhll.personnel.dao.PositionTransferDao;
import com.lxhll.personnel.entity.Employee;
import com.lxhll.personnel.entity.Position;
import com.lxhll.personnel.entity.PositionTransfer;
import com.lxhll.personnel.service.EmployeeService;
import com.lxhll.personnel.service.PositionService;
import com.lxhll.personnel.service.PositionTransferService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * (PositionTransfer)表服务实现类
 *
 * @author makejava
 * @since 2021-07-22 14:52:37
 */
@Service("positionTransferService")
public class PositionTransferServiceImpl extends ServiceImpl<PositionTransferDao, PositionTransfer> implements PositionTransferService {
    @Autowired
    private EmployeeService employeeService;
    @Autowired
    private PositionTransferDao transferDao;
    @Autowired
    private PositionService positionService;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveTransfer(PositionTransfer transfer) {
        //设置调转时间,插入调动信息
        transfer.setTransferDate(LocalDate.now());
        this.save(transfer);
        //将员工信息表的岗位更新为新岗位
        Employee employee=new Employee();
        employee.setId(transfer.getEmployeeId());
        employee.setPositionId(transfer.getNewPositionId());
        employeeService.updateById(employee);
        return true;
    }

    @Override
    public IPage<Map<String, Object>> queryTransfers(Map<String, Object> params) {
        System.out.println("查询参数"+params);
        IPage<Map<String,Object>> page=transferDao.queryTransfer(P.page(params),params); 
        return page;
    }

    @Override
    public PositionTransfer getTransferById(Integer id) {
        PositionTransfer transfer=transferDao.getTransferById(id);
        return transfer;
    }

}
